<?php


namespace app\store\controller\apps\integral;


use app\store\controller\Controller;
use app\store\model\Express as ExpressModel;
use app\store\model\Order as OrderModel;
use app\store\model\OrderRefund as OrderRefundModel;
use app\store\model\store\shop\Clerk as ShopClerkModel;

class Order extends Controller
{
    /**
     * 列表
     */
    private function list($title, $dataType)
    {
        // 订单列表
        $model = new OrderModel;
        $query = ['order_source' => 40];
        $query = array_merge($query, $this->request->param());
        $list = $model->getList($dataType, $query);
        return $this->fetch('index', compact('list', 'title', 'dataType'));
    }

    /**
     * 全部订单列表
     */
    public function index()
    {
        return $this->list('全部订单列表', 'all');
    }

    /**
     * 待付款列表
     */
    public function payList()
    {
        return $this->list('待付款列表', 'pay');
    }

    /**
     * 待发货列表
     */
    public function deliveryList()
    {
        return $this->list('待发货列表', 'delivery');
    }

    /**
     * 待收货列表
     */
    public function receiptList()
    {
        return $this->list('待收货列表', 'receipt');
    }

    /**
     * 已完成列表
     */
    public function completeList()
    {
        return $this->list('已完成列表', 'complete');
    }

    /**
     * 已取消订单列表
     */
    public function cancelList()
    {
        return $this->list('已完成列表', 'cancel');
    }

    /**
     * 订单详情
     * @param $order_id
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function detail($order_id)
    {
        // 订单详情
        $detail = OrderModel::detail($order_id);
        // 物流公司列表
        $expressList = ExpressModel::getAll();
        // 门店店员列表
        $shopClerkList = (new ShopClerkModel)->getList(true);
        return $this->fetch('detail', compact(
            'detail',
            'expressList',
            'shopClerkList'
        ));
    }
}